﻿
module("FallingSquare.init")
test("FallingSquare init", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    equal(5, fallingSquare.center.x, "CenterX of FallingSquare is set");
    equal(6, fallingSquare.center.y, "CenterY of FallingSquare is set");

    var relativeBody="";
    for (var i = 0; i < fallingSquare._relativeBody.length; i++) {
        relativeBody += fallingSquare._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,0) (1,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingSquare is set");

    var body= "";
    for (var i = 0; i < fallingSquare.getBody.length; i++) {
        body += fallingSquare.getBody[i].coordinate.toString() + " ";
    }
    equal("(5,6) (6,6) (5,7) (6,7) ", body, "CenterY of FallingSquare is set");
});

test("FallingSquare moveTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.moveTo(7, 8);

    deepEqual(7, fallingSquare.center.x, "CenterX of FallingSquare is set to new x");
    equal(8, fallingSquare.center.y, "CenterY of FallingSquare is set to new y");

    var relativeBody = "";
    for (var i = 0; i < fallingSquare._relativeBody.length; i++) {
        relativeBody += fallingSquare._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,0) (1,0) (0,1) (1,1) ", relativeBody, "CenterY of FallingSquare is set");

    var body = "";
    for (var i = 0; i < fallingSquare.getBody.length; i++) {
        body += fallingSquare.getBody[i].coordinate.toString() + " ";
    }
    equal("(7,8) (8,8) (7,9) (8,9) ", body, "CenterY of FallingSquare is set");
});

test("FallingSquare moveRight", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.moveRight(); 
    deepEqual(6, fallingSquare.center.x, "CenterX of FallingSquare is set to x+1");
    equal(8, fallingSquare.center.y, "CenterY of FallingSquare is same");
});

test("FallingSquare moveLeft", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.moveLeft();
    deepEqual(4, fallingSquare.center.x, "CenterX of FallingSquare is set to x-1");
    equal(8, fallingSquare.center.y, "CenterY of FallingSquare is same");
});

test("FallingSquare moveUp", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.moveUp();
    equal(5, fallingSquare.center.x, "CenterX of FallingSquare is same");
    equal(7, fallingSquare.center.y, "CenterY of FallingSquare is set to y-1");
});

test("FallingSquare moveDown", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.moveDown();
    equal(5, fallingSquare.center.x, "CenterX of FallingSquare is same");
    equal(9, fallingSquare.center.y, "CenterY of FallingSquare is set to y+1");
});

test("FallingSquare rotate", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.rotate();
    equal(90, fallingSquare.rotation, "Rotation of FallingSquare is set to 90");
});

test("FallingSquare rotate twice", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.rotate();
    equal(90, fallingSquare.rotation, "Rotation of FallingSquare is set to 90");
    fallingSquare.rotate();
    equal(180, fallingSquare.rotation, "Rotation of FallingSquare is set to 180");
});

test("FallingSquare rotateBack", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.rotateBack();
    equal(270, fallingSquare.rotation, "Rotation of FallingSquare is set to 270");   
});

test("FallingSquare rotateTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingSquare = new tetris.FallingSquare(x, y, color);
    fallingSquare.rotateTo(180);
    equal(180, fallingSquare.rotation, "Rotation of FallingSquare is set to 180");
});

